import yaml
import os


class Config(object):
    cur_dir = os.path.dirname(__file__)
    config_file_dir = os.path.abspath(os.path.join(os.path.dirname(cur_dir), "configs"))

    def __init__(self, yaml_file=os.path.join(config_file_dir, "config.yml")):
        self._yaml_file = yaml_file
        self._data = self._load()

    def _load(self):
        with open(self._yaml_file, "r") as f:
            data = yaml.load(f, Loader=yaml.FullLoader)
        return data

    @property
    def key_word_list(self):
        data = self._data
        return data["key_word"]

    @property
    def datetime_range(self):
        data = self._data
        return data["datetime_range"]

    @property
    def chrome_driver_path(self):
        data = self._data
        return data["chrome_driver_path"]

    @property
    def random_num_range(self):
        data = self._data
        return data["random_num_range"]

    @property
    def random_num_range_cms(self):
        data = self._data
        return data["random_num_range_cms"]

    @property
    def crawl_interval(self):
        data = self._data
        return int(data["crawl_interval"])

    @property
    def crawl_depth(self):
        data = self._data
        return int(data["crawl_depth"])


if __name__ == "__main__":
    yaml_reader = Config(yaml_file=os.path.join(Config.config_file_dir, "config.yml"))
    print(yaml_reader.key_word_list)
    print(yaml_reader.chrome_driver_path)
    print(yaml_reader.random_num_range)
    print(yaml_reader.crawl_interval)
